package calculator.handler;


import calculator.operator.*;
import calculator.operator.sequential.RightParenthesisOperator;
import calculator.operator.sp.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class OperatorHandler {

    List<Operator> operators = new ArrayList<>();

    public OperatorHandler(){
        operators.add(new DivisionOperator());
        operators.add(new AddingOperator());
        operators.add(new SubtractOperator());
        operators.add(new PowerOperator());
        operators.add(new MultiplyingOperator());
        operators.add(new RightParenthesisOperator());
        operators.add(new RightParenthesisOperator());
        operators.add(new FactorialOperator());
        operators.add(new ModOperator());
        operators.add(new AbsOperator());
        operators.add(new SqrtOperator());
        operators.add(new SinOperator());
        operators.add(new CosOperator());
        operators.add(new TanOperator());
        operators.add(new LogOperator());
    }

    public Operator getOperator(char op){
        Optional<Operator> optional = operators.stream().filter(o -> o.support(op)).findFirst();

        if (optional.isPresent()) {
            return optional.get();
        }

        throw new RuntimeException("非法操作符: '" + op + "'");

    }


}
